本章课程PDF,视频(油管B站)。

Why CNN for Image

  • Some patterns are much smaller than the whole image. A neuron does not have to see the whole image to discover the pattern. Connecting to small region with less parameters.
  • The same patterns appear in different regions.
  • Subsampling the pixels will not change the object. We can subsample the pixels to make image smaller. Less parameters for the network to process the image.

The whole CNN


Convolution Layer解决前两个Property,Max Pooling Layer解决第三个Property。

CNN – Convolution

在convolution layer里有一组filter,每个filter就是一个matrix,matrix里面的每一个element的值就是network的parameter,跟neural的weight、bias一样,是必须学出来的,并不是人设计的。

每次filter挪动的距离叫stride,需要手动设置。

方便理解卷积操作,可以看动图

CNN – Colorful image

image好几个matrix叠在一起,是一个立方体,filter也是立方体。

Convolution v.s. Fully Connected


CNN – Max Pooling

Max pooling就是做subsampling,它是把卷积过后提取之后的特征看做一个矩阵,并在这个矩阵上划分出几个不重合的区域,然后在每个区域上计算该区域内特征的均值或最大值,然后用这些均值或最大值参与后续的训练。

convolution有多少个filter,output就有多少个filter。


CNN in Keras



What does CNN learn?

设第k个filter的活跃度为$a^k$,固定参数,用梯度上升法求使$a^k$最大的input image。

得到的结果是,使各个filter活跃度最大的image是各种条纹。这层filter看的还是局部信息。

flatten后的filter活跃度最大的image,就显示出了各种轮廓,说明这些filter看的是整体信息。

如果考虑的是output,使某一维度的output最大,如果某一张image可以让对应到数字1的output layer的neural的output最大,那张image应该看起来像是数字1,但实际是电子坏掉的雪花图。(可以对x加上constraint,使图片看起来更像是数字。)





Deep Dream

将一张image作为CNN的输入,将CNN某个hidden layer的output(vector)拿出来,让其值正的更正、负的更负,把它作为新的image的目标。


Deep Style



More Application

Playing Go:棋盘作为image,有开篇所讲的前两个特点,但没有第三个特点,所以阿尔法狗没有Max Pooling。
Speech:CNN的filter只会在频谱的频率方向扫描,不会在时间方向扫描。
Text:CNN的filter只会在sentence matrix的时间方向扫描,不会在embedding dimension方向扫描。

在具体场景应用CNN时,如何设计CNN的结构,需要考虑场景本身的性质特点。

如果本博文对您有帮助,可以赞助支持一波博主~